// NACL MOD TRACK "third_party/nacl-glibc/sysdeps/nacl/fxstat.c"

#include <errno.h>
#include <nacl_stat.h>
#include <irt_syscalls.h>
#include <stddef.h>
#include <sys/stat.h>

int fstat(int fd, struct stat *buf) {
  ENOSYS_IF_NULL(__nacl_irt_fstat)

  if (buf == NULL) {
    errno = EFAULT;
    return -1;
  }

  struct nacl_abi_stat nacl_buf;
  int result = __nacl_irt_fstat (fd, (struct stat*) &nacl_buf);
  if (result != 0) {
    errno = __nacl_abi_errno_to_errno(result);
    return -1;
  }

  __nacl_abi_stat_to_stat (&nacl_buf, buf);
  return 0;
}
